<template>
  <div class="top-bar">
    <!-- <div
      class="wind-legend-warp"
      v-if="
        monitoringStore.gdskjcCurrentSelect == 'WIND' ||
        predictionStore.gdskjcCurrentActive == 'WIND'
      "
    >
      <div class="name">风级</div>
      <div class="left">
        <div
          class="color"
          v-for="(color, index) in windColorList"
          :key="index"
          :style="{ backgroundColor: color.stop }"
        ></div>
      </div>
      <div class="right">
        <div class="num" v-for="(num, index) in windColorList" :key="index">
          {{ num.value }}
        </div>
      </div>
    </div> -->
    <div class="legend-warp" v-if="colorList.length">
      <!-- <div
        class="name"
        v-if="
          monitoringStore.gdskjcCurrentSelect == 'WIND' ||
          predictionStore.gdskjcCurrentActive == 'WIND'
        "
      >
        风速
      </div> -->
      <div class="left">
        <div
          class="color"
          v-for="(color, index) in colorList"
          :key="index"
          :style="{ backgroundColor: color.stop }"
        ></div>
      </div>
      <div class="right">
        <div class="num" v-for="(num, index) in colorList" :key="index">
          {{ num.value }}
        </div>
      </div>
    </div>
    <div
      class="color-legend-line"
      v-if="forestryArr.length && fireModuleVisible.ybModule"
    >
      <div
        v-for="(color, index) in forestryArr"
        :key="index"
        :style="{ backgroundColor: color }"
      >
        {{ initTitle[index] }}
      </div>
    </div>
    <div class="location" @click="initCamera">
      <img src="../images/pos.png" alt="" />
    </div>
    <div class="zoom">
      <div :class="['state-switch', isLaunch ? 'state-active' : '']">
        <div>
          <div
            :class="['state', isState == 'wx' ? 'stateA' : '']"
            @click="handleChangeMapStyle('wx')"
          >
            <img
              src="../images/wxbg.png"
              :style="{ borderRadius: isLaunch ? '0' : '50%' }"
              class="mapimg"
              alt=""
            />
          </div>
          <div class="name" v-show="isLaunch">卫星</div>
        </div>
        <div>
          <div
            :class="['state', isState == 'xz' ? 'stateA' : '']"
            @click="handleChangeMapStyle('xz')"
          >
            <img
              src="../images/xzbg.png"
              :style="{ borderRadius: isLaunch ? '0' : '50%' }"
              class="mapimg"
              alt=""
            />
          </div>
          <div class="name" v-show="isLaunch">行政地图</div>
        </div>
        <img v-if="!isLaunch" @click="launch" src="../images/open.png" alt="" />
        <img v-if="isLaunch" @click="launch" src="../images/put.png" alt="" />
      </div>
      <div class="zoom-box">
        <div @click="enlarge">
          <img src="../images/jia.png" alt="" />
        </div>
        <div class="line"></div>
        <div @click="narrow">
          <img src="../images/jian.png" alt="" />
        </div>
      </div>
    </div>
    <div class="position-wrap">
      <div class="position">
        <p>经度：{{ lng }}</p>
        <p>纬度：{{ lat }}</p>
      </div>
      <div class="size">
        {{ baseLeafletMapStore.kilometre }}
        <img src="../images/size.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import * as L from 'leaflet'
import { getJSON } from '@quickearth/core'
import { useBaseLeafletMapStore } from '@/store/modules/baseLeafletMap'
import { usedisasterStore } from '@/pages/geological-disaster/store/store'
import { useWarningStore } from '@/pages/warning/store/store'
import { useMonitoringStore } from '@/pages/integrated-monitoring/store/store'
import { usePredictionStore } from '@/pages/conventional-fine-forecasting/store/store'
import { fireInsuranceStore } from '@/pages/forestry/store/store'
import yulinGeojson from '@/assets/data/yulin1.json'
const baseLeafletMapStore = useBaseLeafletMapStore()
const disasterStore = usedisasterStore()
const warningStore = useWarningStore()
const monitoringStore = useMonitoringStore()
const predictionStore = usePredictionStore()
const fireStore = fireInsuranceStore()
const fireModuleVisible = computed(() => fireStore.moduleVisible)
const colorList = computed(() => {
  let arr = []
  if (window.location.hash == '#/integrated-monitoring') {
    monitoringStore.gdskjcOptions.forEach(res => {
      if (res.value == monitoringStore.gdskjcCurrentSelect) {
        for (let self of res.legendStops.stops) {
          if (self.value != -9999) {
            arr.push(self)
          }
        }
      }
    })
  } else if (window.location.hash == '#/conventional-fine-forecasting') {
    predictionStore.gdskjcOptions.forEach(res => {
      if (res.value == predictionStore.gdskjcCurrentActive) {
        if (res.legendStops.stops) {
          for (let self of res.legendStops.stops) {
            if (self.value != -9999) {
              arr.push(self)
            }
          }
        }
      }
    })
  }

  return arr
})
const windColorList = ref([])
const forestryArr = computed(() => {
  if (window.location.hash == '#/forestry') {
    return [
      'rgba(20,172,228,1)',
      'rgba(100,186,48,1)',
      'rgba(236,251,4,1)',
      'rgba(248,163,43,1)',
      'rgba(207,1,25,1)'
    ]
  } else {
    return []
  }
})
const initTitle = ref(['无危险', '存在危险', '较危险', '很危险', '非常危险'])

const lng = ref(0)
const lat = ref(0)
useEventBus('currentMapPositionLatLng').on((lngData, latData) => {
  lng.value = lngData
  lat.value = latData
})

const componentVisible = inject('componentVisible')
//放大
const enlarge = () => {
  useEventBus('handleEnlarge').emit()
}
//缩小
const narrow = () => {
  useEventBus('handleNarrow').emit()
}
//展开
const isLaunch = ref(false)
const launch = () => {
  isLaunch.value = !isLaunch.value
}
const isState = ref('wx')
// 图层处理
const handleChangeMapStyle = val => {
  isState.value = val
  switch (val) {
    case 'wx':
      useEventBus('handleRemoveLayer').emit('tdtNormal')
      const tdtNormalTileLayer = L.tileLayer(
        'http://172.18.77.23:80/sfzxGis/tdtSatellite/{z}/{x}/{y}.jpg'
      )
      useEventBus('handleAddLayer').emit(tdtNormalTileLayer, 'tdtSatellite')
      break
    case 'xz':
      useEventBus('handleRemoveLayer').emit('tdtSatellite')
      const tdtSatelliteTileLayer = L.tileLayer(
        'http://172.18.77.23:80/sfzxGis/tdtNormal/{z}/{x}/{y}.jpg'
      )
      useEventBus('handleAddLayer').emit(tdtSatelliteTileLayer, 'tdtNormal')
      break
  }
}
const initCamera = () => {
  useEventBus('handleInitCameraPosition').emit()
  useEventBus('handleRemoveLayer').emit('taiyuanqxWhite')
  useEventBus('handleRemoveLayer').emit('taiyuanshiWhite')
  useEventBus('handleRemoveLayer').emit('yulinWhite')
  useEventBus('handleRemoveLayer').emit('yulinSideWhite')
  disasterStore.componentsVisible.labels = '全部'
  warningStore.componentsVisible.labels = '全部'
  useEventBus('handleInitLayer').emit(yulinGeojson, 'yulinWhite')
}
onMounted(() => {
  handleChangeMapStyle('xz')
})
</script>

<style scoped lang="scss">
.top-bar {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20%;
  height: 200px;
  background-color: transparent;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  box-sizing: border-box;
  .color-legend {
    width: 21px;
    height: 400px;
    border-radius: 19px 19px 19px 19px;
    position: absolute;
    right: 100px;
    bottom: 157px;
    border: 1px solid rgba($color: #ffffff, $alpha: 0.2);
  }
  .legend-warp,
  .wind-legend-warp {
    width: 50px;
    height: auto;
    position: absolute;
    right: 21px;
    bottom: 157px;
    // border: 1px solid #999;
    // display: flex;
    .left {
      width: 25px;
      height: 100%;
      // display: inline-block;
      float: left;
      .color {
        width: 25px;
        height: 25px;
        div {
          width: 100%;
          height: 100%;
        }
      }
    }
    .right {
      width: 25px;
      height: 100%;
      display: inline-block;
      .num {
        width: 25px;
        height: 25px;
        text-align: center;
        line-height: 25px;
        color: #fff;
      }
    }
    .name {
      color: #fff;
    }
  }
  .wind-legend-warp {
    right: 100px;
  }
  .color-legend-line {
    width: 370px;
    height: 20px;
    border-radius: 10px 10px 10px 10px;
    position: absolute;
    right: 60px;
    bottom: 125px;
    display: flex;
    div {
      width: 75px;
      text-align: center;
      line-height: 20px;
      font-weight: 400;
      font-size: 12px;
      color: #ffffff;
      line-height: 20px;
      font-style: normal;
      text-shadow: 0px 0px 2px #000;
    }
    div:first-child {
      border-radius: 10px 0 0 10px;
    }
    div:last-child {
      border-radius: 0 10px 10px 0;
    }
  }
  .location {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    position: absolute;
    right: 17px;
    bottom: 119px;
    background: rgba(0, 17, 46, 0.66);
    box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
    border: 1px solid rgba(255, 255, 255, 0.23);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    img {
      width: 16px;
      height: 16px;
    }
  }
  .zoom {
    width: 100%;
    min-height: 60px;
    display: flex;
    justify-content: flex-end;
    align-items: end;
    position: absolute;
    right: 17px;
    bottom: 50px;
    .zoom-box {
      width: 30px;
      height: 60px;
      background: rgba(0, 17, 46, 0.66);
      box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
      // border-radius: 15px 15px 15px 15px;
      border: 1px solid rgba(255, 255, 255, 0.23);
      padding: 8px 5px;
      box-sizing: border-box;
      div:first-child {
        width: 100%;
        height: 49%;
        display: flex;
        justify-content: center;
        align-items: start;
        cursor: pointer;
        img {
          width: 14px;
          height: 14px;
        }
      }
      div:last-child {
        width: 100%;
        height: 40%;
        display: flex;
        justify-content: center;
        align-items: end;
        cursor: pointer;
        img {
          width: 14px;
          height: 1.75px;
        }
      }

      .line {
        width: 100%;
        height: 1px;
        background-color: #fff;
        opacity: 0.18;
      }
    }
    .state-switch {
      width: 151px;
      height: 60px;
      background: rgba(10, 146, 253, 0.09);
      box-shadow: 0px 0px 8px 1px #0a92fd;
      border-radius: 6px 6px 6px 6px;
      border: 1px solid #0a92fd;
      margin-right: 18px;
      padding: 9px 5px;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: space-around;
      .name {
        color: #fff;
        font-size: 12px;
        text-align: center;
        margin: 5px 0;
      }
      .state {
        width: 44px;
        height: 44px;
        background: #ffffff;
        border-radius: 22px 22px 22px 22px;
        border: 1px solid #707070;
        margin-right: 10px;
        cursor: pointer;
      }
      .stateA {
        border: 1px solid #00ccff;
      }
      img {
        width: 14px;
        height: 14px;
        margin-right: 0px;
        cursor: pointer;
      }
      .mapimg {
        width: 100%;
        height: 100%;
      }
    }
    .state-active {
      width: 244px;
      height: 122px;
      background: rgba(0, 13, 35, 0.76);
      box-shadow: 0px 0px 6px 1px rgba(0, 204, 255, 0.77),
        inset 0px 0px 14px 1px #00ccff;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #2c96cd;
      padding: 9px 5px;
      .state {
        width: 80px;
        height: 80px;
        background: #ffffff;
        border-radius: 10px 10px 10px 10px;
        border: 1px solid #707070;
      }
      .stateA {
        border: 1px solid #00ccff;
      }
    }
  }
  .position-wrap {
    position: absolute;
    bottom: 6px;
    right: 17px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .position {
      display: flex;
      align-items: center;
      font-size: 14px;

      p {
        // width: 150px;
        margin-right: 10px;
        color: #ffffff;
      }
    }
    .size {
      width: 80px;
      height: 30px;
      background: rgba(0, 17, 46, 0.66);
      box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
      border-radius: 15px 15px 15px 15px;
      border: 1px solid rgba(255, 255, 255, 0.23);
      font-size: 12px;
      color: #ffffff;
      line-height: 1.5;
      text-align: center;
      position: relative;
      img {
        width: 50px;
        height: 8px;
        position: absolute;
        bottom: 3px;
        left: 50%;
        transform: translateX(-50%);
      }
    }
  }
}
</style>
